﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using H2.Streams;

namespace Mystery.Unicode
{
    public class UnicodeTag
    {
        public int Offset;

        public ushort EnglishStringIndex;
        public ushort EnglishStringCount;

        public ushort JapaneseStringOffset;
        public ushort JapaneseStringCount;

        public ushort GermanStringOffset;
        public ushort GermanStringCount;

        public ushort FrenchStringOffset;
        public ushort FrenchStringCount;

        public ushort SpanishStringOffset;
        public ushort SpanishStringCount;

        public ushort ItalianStringOffset;
        public ushort ItalianStringCount;

        public ushort KoreanStringOffset;
        public ushort KoreanStringCount;

        public ushort ChineseStringOffset;
        public ushort ChineseStringCount;

        public ushort PortugueseStringOffset;
        public ushort PortugueseStringCount;

        public static UnicodeTag Read(MapStream map)
        {
            UnicodeTag tag = new UnicodeTag();
            
            tag.Offset = (int)map.Position;

            map.Position += 16;

            tag.EnglishStringIndex = map.ReadUInt16();
            tag.EnglishStringCount = map.ReadUInt16();

            tag.JapaneseStringOffset = map.ReadUInt16();
            tag.JapaneseStringCount = map.ReadUInt16();

            tag.GermanStringOffset = map.ReadUInt16();
            tag.GermanStringCount = map.ReadUInt16();

            tag.FrenchStringOffset = map.ReadUInt16();
            tag.FrenchStringCount = map.ReadUInt16();

            tag.SpanishStringOffset = map.ReadUInt16();
            tag.SpanishStringCount = map.ReadUInt16();

            tag.ItalianStringOffset = map.ReadUInt16();
            tag.ItalianStringCount = map.ReadUInt16();

            tag.KoreanStringOffset = map.ReadUInt16();
            tag.KoreanStringCount = map.ReadUInt16();

            tag.PortugueseStringOffset = map.ReadUInt16();
            tag.PortugueseStringCount = map.ReadUInt16();

            return tag;
        }

        public static void Write(MapStream map, UnicodeTag tag)
        {
            map.Position += 16;

            map.Write(tag.EnglishStringIndex);
            map.Write(tag.EnglishStringCount);

            map.Write(tag.JapaneseStringOffset);
            map.Write(tag.JapaneseStringCount);

            map.Write(tag.GermanStringOffset);
            map.Write(tag.GermanStringCount);

            map.Write(tag.FrenchStringOffset);
            map.Write(tag.FrenchStringCount);

            map.Write(tag.SpanishStringOffset);
            map.Write(tag.SpanishStringCount);

            map.Write(tag.ItalianStringOffset);
            map.Write(tag.ItalianStringCount);

            map.Write(tag.KoreanStringOffset);
            map.Write(tag.KoreanStringCount);

            map.Write(tag.PortugueseStringOffset);
            map.Write(tag.PortugueseStringCount);
        }
    }
}
